class Iterator {
  constructor(array) {
    this.array = array
    this.index = 0
  }
  next() {
    if (this.index >= this.array.length) {
      return {
        done: true,
        value: 'undefined'
      }
    }
    return {
      done: false,
      value: this.array[this.index++]
    }
  }
}

let arr = [10, 20, 30]
let ctor = new Iterator(arr)
console.log(ctor.next()) //=> {done: false, value: 10}
console.log(ctor.next()) //=> {done: false, value: 20}
console.log(ctor.next()) //=> {done: false, value: 30}
console.log(ctor.next()) //=> {done: true, value: undefined}
console.log(ctor.next()) //=> {done: true, value: undefined}
